import { observable, action } from "mobx";
import { template } from '../../apis/excelTemplate';
export default class ExcelTemplateViewStore {
    @observable loading = false;
    @observable isInit = false;
    @observable title = '';
    @action updateLocationQuery = (query) => {
        this.query = query;
        this.loadTemplate(query.id);
    }
    @action initWorkbook = (workbook) => {
        this.isInit = true;
        this.workbook = workbook;
    }
    @action loadTemplate = (key) => {
        this.loading = true;
        template(key).then(this.setTemplate)
    }

    @action setTemplate = (template) => {
        this.title = template.name;
        if (this.workbook) {
            this.workbook.fromJSON(JSON.parse(template.json), false);
            this.loading = false;
        } else {
            setTimeout(() => {
                this.setTemplate(template);
            }, 100);
        }
    }
}